package net.lzzy.practices.web.models;

import lombok.Getter;
import lombok.Setter;
import net.lzzy.practices.entities.User;
import net.lzzy.practices.utils.JwtUtil;

import java.util.UUID;

/**
 * @author admin
 */
@Getter
@Setter
public class VmUser {
    private UUID id;

    private String nikeName;

    private String userName;

    private String password;

    private String phone;

    private String email;

    private String avatar;

    private String token;

    private int type;

    private VmUser(){}
//构造器，静态工厂方法
    private  VmUser(User user){
    id =user.getId();
    nikeName= user.getNickName();
    userName= user.getUserName();
    password= user.getPassword();
    phone= user.getPhone();
    email= user.getEmail();
    avatar= user.getAvatar();
    type= user.getType();
    }

    public  static VmUser apiLogin(User user){
        VmUser vm = new VmUser(user);
        vm.setToken(JwtUtil.createToken(user.getId()+""));
        return vm;
    }

    public static  VmUser create(User user,boolean admin){
        VmUser vm = new VmUser(user);
        if (!admin){
            vm.setUserName("***");
            vm.setType(User.TYPE_STUDENT);
        }
        return vm;
    }
}
